package com.example.demo.Controller;

import com.example.demo.Common.Category;
import com.example.demo.Common.Result;
import com.example.demo.Proj.CategoryPageParam;
import com.example.demo.Proj.PageReslut;
import com.example.demo.Service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/page")
    public Result getCategoryPage(CategoryPageParam categoryPageParam){
        log.info("CategoryPage： " + categoryPageParam);
        PageReslut pageReslut = categoryService.getCategoryPage(categoryPageParam);
        log.info("pageResult: " + pageReslut);
        return Result.success(pageReslut);
    }

    @PostMapping()
    public Result addCategory(@RequestBody Category category){
        log.info("add parameter:" + category);
        categoryService.addCategory(category);
        return Result.success();
    }

    @PutMapping()
    public Result editCategory(@RequestBody Category category){
        log.info("edit parameter: " + category);
        categoryService.editCategory(category);
        return Result.success();
    }

    @DeleteMapping
    public Result deleCategory(@RequestParam Long id){
        log.info("delete id: " + id);
        categoryService.deleCategory(id);
        return Result.success();
    }

    @PostMapping("/status/{status}")
    public Result enableOrDisableEmployee(@PathVariable Integer status, @RequestParam Long id){
        log.info("id: " + id + ", set status: " + status);
        categoryService.enableOrDisableEmployee(id, status);
        return Result.success();
    }
}
